<?php
/**
 * 公共控制器
 * 输出勋章
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\ApiController;
use Think\Exception;

class CommonController extends ApiController
{
    /**
     * 获取是否关注某人
     * @param int $uid 被关注的用户的userid
     */
    public function getFetchAttention($uid = null)
    {
        $attention_uid = $uid;
        $fans_uid = $this->userId;
        try {
            $request = D('MemberFans')->is_follow($attention_uid, $fans_uid);
            if ($request > 0) {
                $this->myApiPrint('success', 200, 1);
            } else {
                $this->myApiPrint('error', 201, 0);
            }
        } catch (Exception $exception) {
            $this->myApiPrint('error', 400, 0);
        }
    }

    /**
     * 获取专家等级
     */
    public function getExpertType()
    {
        $data = D('ExpertLevelProfile')->get_expert_level_list();
        if (!$data) {
            $request['msg'] = C('STATUS')['230'];
            $request['code'] = 201;
            $request['result'] = [];
        } else {
            $request['msg'] = C('STATUS')['200'];
            $request['code'] = 200;
            $request['result'] = $data;
        }
        return $this->myApiPrint($request['msg'], $request['code'], $request['result']);
    }

    /**
     * 获取用户金币
     */
    public function getGold()
    {
        $id = $this->userId;
        $gold['gold'] = D('MemberProfile')->get_member_gold_int($id);
        if (!isset($gold)) {
            $request['msg'] = C('STATUS')['230'];
            $request['code'] = 201;
            $request['result'] = [];
        } else {
            $request['msg'] = C('STATUS')['200'];
            $request['code'] = 200;
            $request['result'] = $gold;
        }
        return $this->myApiPrint($request['msg'], $request['code'], $gold);
    }
}
